CodeCodeEvolution Coder


The following notebook recieved a score of 0.4 because of the reasons listed below.

  • The goal of the notebook seems to obviously to create an unsupervised classifier of housing sales. (directed analysis)
  • logical steps are isolated to individual code cells
  • minimal code replication

In [51]:
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.linear_model import LogisticRegression
from sklearn.tree import DecisionTreeClassifier
from sklearn.neighbors import KNeighborsClassifier
from sklearn.metrics import mean_squared_error
In [52]:
kc_df = pd.DataFrame()
In [53]:
kc_df = pd.read_csv('https://raw.githubusercontent.com/javed24/House-Sales-Prediction/master/dataset/kc_house_data.csv')
In [54]:
print(kc_df.shape)
print(kc_df[:2])
(21613, 21)
           id             date     price  bedrooms  bathrooms  sqft_living  \
0  7129300520  20141013T000000  221900.0         3       1.00         1180   
1  6414100192  20141209T000000  538000.0         3       2.25         2570   

   sqft_lot  floors  waterfront  view     ...      grade  sqft_above  \
0      5650     1.0           0     0     ...          7        1180   
1      7242     2.0           0     0     ...          7        2170   

   sqft_basement  yr_built  yr_renovated  zipcode      lat     long  \
0              0      1955             0    98178  47.5112 -122.257   
1            400      1951          1991    98125  47.7210 -122.319   

   sqft_living15  sqft_lot15  
0           1340        5650  
1           1690        7639  

[2 rows x 21 columns]
In [55]:
list(kc_df.columns.values)
Out[55]:
['id',
 'date',
 'price',
 'bedrooms',
 'bathrooms',
 'sqft_living',
 'sqft_lot',
 'floors',
 'waterfront',
 'view',
 'condition',
 'grade',
 'sqft_above',
 'sqft_basement',
 'yr_built',
 'yr_renovated',
 'zipcode',
 'lat',
 'long',
 'sqft_living15',
 'sqft_lot15']
In [56]:
features = ['bedrooms','bathrooms','sqft_living','sqft_lot','floors','waterfront','view','condition','grade','sqft_above','sqft_basement','yr_built']
#features = list(kc_df.columns.values)
In [57]:
feature_matrix = kc_df[features]
lable_vector = kc_df['price']
feature_matrix.head()
Out[57]:
bedrooms bathrooms sqft_living sqft_lot floors waterfront view condition grade sqft_above sqft_basement yr_built
0 3 1.00 1180 5650 1.0 0 0 3 7 1180 0 1955
1 3 2.25 2570 7242 2.0 0 0 3 7 2170 400 1951
2 2 1.00 770 10000 1.0 0 0 3 6 770 0 1933
3 4 3.00 1960 5000 1.0 0 0 5 7 1050 910 1965
4 3 2.00 1680 8080 1.0 0 0 3 8 1680 0 1987

CodeCodeEvolution Coder


  • The code comments below show signs of parallel iterations (i.e. decision tree classifier, logistic regression...etc).
  • There's a clear picture of how this was flow is connected via the structure of the code cells.
  • Lack of labels or code comments suggest that intent was not communication or re-use

In [58]:
X_train, X_test, y_train, y_test = train_test_split(feature_matrix, lable_vector, test_size=0.3, random_state=3)
In [59]:
# Initialize classifiers 
#my_logreg = LogisticRegression()

my_linear = LinearRegression()

#my_decisiontree = DecisionTreeClassifier()

#k = 5
#knn = KNeighborsClassifier(n_neighbors=k)
In [60]:
#knn.fit(X_train, y_train)

#my_decisiontree.fit(X_train, y_train)

#my_logreg.fit(X_train, y_train)

my_linear.fit(X_train, y_train)
Out[60]:
LinearRegression(copy_X=True, fit_intercept=True, n_jobs=1, normalize=False)
In [61]:
# printing Theta0 using attribute "intercept_":
print(my_linear.intercept_)

# printing [Theta1, Theta2, Theta3] using attribute "coef_":
print(my_linear.coef_)
coef_list = my_linear.coef_
coef_list.sort()
print(coef_list)
6461472.20531
[ -3.63453263e+04   4.59850421e+04   1.12835313e+02  -2.27124562e-01
   2.81322640e+04   5.29438621e+05   4.93081587e+04   1.81986059e+04
   1.23643988e+05   5.61046684e+01   5.67306448e+01  -3.70924829e+03]
[ -3.63453263e+04  -3.70924829e+03  -2.27124562e-01   5.61046684e+01
   5.67306448e+01   1.12835313e+02   1.81986059e+04   2.81322640e+04
   4.59850421e+04   4.93081587e+04   1.23643988e+05   5.29438621e+05]
In [62]:
#predict testing data

#y_predict_knn = knn.predict(X_test)

#y_predict_dt = my_decisiontree.predict(X_test)

#y_predict_lr = my_logreg.predict(X_test)
y_predict_ln = my_linear.predict(X_test)
print(y_predict_ln)
#print(y_predict_lr)
#print(y_predict_dt)
#print(y_predict_knn)
[  1.16414960e+09   1.27250407e+09   1.22612723e+09 ...,   1.12727988e+09
   1.22756097e+09   1.08228925e+09]
In [63]:
# from sklearn.metrics import accuracy_score

# score_lr = accuracy_score(y_test, y_predict_lr.argmax(axis=1))
# #score_dt = accuracy_score(y_test, y_predict_dt)
# #score_knn = accuracy_score(y_test, y_predict_knn)
# print("Logistic Regression:>>> ",score_lr)
# #print("Decision Tree>> ",score_dt)
# #print("KNN>>>> ",score_knn)
In [64]:
error = mean_squared_error(y_test, y_predict_ln)
print(error)
1.38511026508e+18
In [65]:
root_mean_square_error = np.sqrt(error)
print(root_mean_square_error)
1176907075.8
In [ ]: